﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ChuangDu_Spirit_QGB_BLL;
using ChuangDu_Spirit_QGB_IBLL;
using ChuangDu_Spirit_QGB_Model;
using ChuangDu_Spirit_QGB_BLLContainer;
using Webdiyer.WebControls.Mvc;

namespace ChuangDu_Spirit_QGB.Areas.Sprintzbh.Controllers
{

    public class PschanceController : Controller
    {
        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPschanceBLL userbll = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.PschanceBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPschanceBLL>();

        // GET: Sprintzbh/Zbh
        /// <summary>
        /// 项目销售机会        
        /// </summary>
        /// 
        public ActionResult Welcome()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public int PschanceDetails()
        {
            var ids = Request["ids"];
            int rows = 0;
            string[] i = ids.Split(',');
            PschanceInfo m = new PschanceInfo();
            foreach (string x in i)
            {
                m.Id = Convert.ToInt32(x);
                rows = rows + userbll.Delete(m);
            }

            if (rows > 0)
                return 1;
            else
                return 0;
        }
        public int PschanceEdit(PschanceInfo t)
        {
            int i = userbll.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int PschanceAdd(PschanceInfo t)
        {

            int i = userbll.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult PschanceShow(int id = 1)
        {
            //获取id值  根据复选框
            //var ids = Request["ids"];
            IEnumerable<PschanceInfo> list;
            list = userbll.show().ToList();
            //显示单行数据，获取修改的数据
            
            //if (ids != null)
            //{
            //  var s = list.Where(m => m.Id == Convert.ToInt32(ids)).FirstOrDefault();
            //  ViewBag.PschanceUpt = s;
            //}
            //else
            //{
            //    list = userbll.show().ToList();
            //}
            
            ViewBag.PschanceName = new SelectList(userbll1.show(), "Id", "PschanceName");



            var name = Request["name"];
            if (name != null)
            {
                list = list.Where(m => m.PschansName == name).ToList();
            }
            return View(list.ToPagedList(id, 10));
        }

        /// <summary>
        /// 销售机会---类型
        /// </summary>
        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPstypeBLL userbll1 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.PstypeBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPstypeBLL>();

        // GET: Sprintzbh/Zbh

        //[ValidateInput(false)]
        public int PstypeDetails(PschanceType t)
        {
            int i = userbll1.Delete(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int PstypeEdit(PschanceType t)
        {
            int i = userbll1.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int PstypeAdd(PschanceType t)
        {
            int i = userbll1.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult PstypeShow()
        {
            IEnumerable<PschanceType> list = userbll1.show().ToList();
            return View(list);
        }

        /// <summary>
        /// 销售机会---来源
        /// </summary>
        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPscSourceBLL userbll2 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.PscSourceBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IPscSourceBLL>();

        // GET: Sprintzbh/Zbh


        public int PscsourceDetails(PscSourceInfo t)
        {
            int i = userbll2.Delete(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int PscsourceEdit(PscSourceInfo t)
        {
            int i = userbll2.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int PscsourceAdd()
        {
            PscSourceInfo t = new PscSourceInfo();

            int i = userbll2.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult PscsourceShow()
        {

            IEnumerable<PscSourceInfo> list = userbll2.show().ToList();
            return View(list);
        }



        //详细需求分析

        // GET: Sprintzbh/Dneed

        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IDneedBLL userbll3 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.DneedBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IDneedBLL>();



        public int DneedDetails()
        {
            var ids = Request["ids"];
            int rows = 0;
            string[] i = ids.Split(',');
            DneedInfo m = new DneedInfo();
            foreach (string x in i)
            {
                m.Id = Convert.ToInt32(x);
                rows = rows + userbll3.Delete(m);
            }

            if (rows > 0)
                return 1;
            else
                return 0;
        }
        public int DneedEdit(DneedInfo t)
        {
            int i = userbll3.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int DneedAdd(DneedInfo t)
        {
            int i = userbll3.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult DneedShow(int id = 1)
        {

            IEnumerable<DneedInfo> list = userbll3.show().ToList().ToPagedList(id, 10);
            return View(list);
        }

        // GET: Sprintzbh/Sem
        /// <summary>
        /// 解决方案管理0
        /// </summary>

        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.ISemBLL userbll4 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.SemBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.ISemBLL>();


        public int SemDetails()
        {
            var ids = Request["ids"];
            int rows = 0;
            string[] i = ids.Split(',');
            SemInfo m = new SemInfo();
            foreach (string x in i)
            {
                m.Id = Convert.ToInt32(x);
                rows = rows + userbll4.Delete(m);
            }

            if (rows > 0)
                return 1;
            else
                return 0;
        }
        public int SemEdit(SemInfo t)
        {
            int i = userbll4.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;

        }
        public int SemAdd(SemInfo t)
        {
            int i = userbll4.Add(t);

            if (i > 0)
                return 1;
            else
                return 0;

        }
        public ActionResult SemShow(int id = 1)
        {

            IEnumerable<SemInfo> list = userbll4.show().ToList().ToPagedList(id, 10);
            return View(list);
        }

        /// <summary>
        /// 竞争对手管理
        /// </summary>
        // GET: Sprintzbh/Crm

        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.ICrmBLL userbll5 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.CrmBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.ICrmBLL>();
        public int CrmDetails()
        {
            var ids = Request["ids"];
            int rows = 0;
            string[] i = ids.Split(',');
            CrmInfo m = new CrmInfo();
            foreach (string x in i)
            {
                m.Id = Convert.ToInt32(x);
                rows = rows + userbll5.Delete(m);
            }

            if (rows > 0)
                return 1;
            else
                return 0;
        }
        public int CrmEdit(CrmInfo t)
        {
            int i = userbll5.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int CrmAdd(CrmInfo t)
        {
            int i = userbll5.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult CrmShow(int id = 1)
        {

            IEnumerable<CrmInfo> list = userbll5.show().ToList().ToPagedList(id, 10);
            return View(list);
        }

        /// <summary>
        /// 历史报价单
        /// </summary>

        private ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IOfferBLL userbll6 = BLLContainer.Resolve<ChuangDu_Spirit_QGB_BLL.ZhengBll.OfferBLL, ChuangDu_Spirit_QGB_IBLL.ZhengIbll.IOfferBLL>();


        public int OfferDetails()
        {
            var ids = Request["ids"];
            int rows = 0;
            string[] i = ids.Split(',');
            OfferInfo m = new OfferInfo();
            foreach (string x in i)
            {
                m.Id = Convert.ToInt32(x);
                rows = rows + userbll6.Delete(m);
            }

            if (rows > 0)
                return 1;
            else
                return 0;
        }
        public int OfferEdit(OfferInfo t)
        {
            int i = userbll6.Update(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public int OfferAdd(OfferInfo t)
        {
            int i = userbll6.Add(t);
            if (i > 0)
                return 1;
            else
                return 0;
        }
        public ActionResult OfferShow(int id = 1)
        {

            IEnumerable<OfferInfo> list = userbll6.show().ToPagedList(id, 10);
            return View(list);
        }
    }
}